package Webpage;
import AutoTest.AutoFun;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import java.time.Duration;
import java.util.Scanner;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-09-05
 * Time: 17:36
 */
//测试登录功能
public class Login {
    private WebDriver driver=null;
    private String url="http://8.155.1.153/?s=user/loginInfo.html";
    private Scanner scanner=new Scanner(System.in);
    private String str=null;
    public Login(){
    }
    public void test()throws InterruptedException{
        driver= AutoFun.getDriver(url);
        str=scanner.next();
        //test1();//测试账号错误，其余正确
        System.out.println("test1执行完成");
        //test2();//测试密码错误，其余正确
        System.out.println("test2执行完成");
        //test3();//测试验证码错误，其余正确
        System.out.println("test3执行完成");
        test4();//测试正确登录
        System.out.println("test4执行完成");
        System.out.println("登陆功能测试完成");
    }
    private void test1(){
        //未填写用户名
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("123456");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys(str);
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
        //用户名错误
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("11111");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("123456");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys(str);
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
        //用户命长度<2字符
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("1");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("123456");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys(str);
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
        //用户名长度>18字符
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("11111111111111111111");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("123456");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys(str);
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
    }
    private void test2(){
        //未填写密码
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("4059");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys(str);
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
        //密码错误
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("4059");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("1111111");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys(str);
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
        //密码长度<6
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("4059");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("111");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys(str);
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
        //密码长度>18
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("1");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("11111111111111111111");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys(str);
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
    }
    private void test3(){
        //未填写验证码
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("4059");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("123456");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
        //验证码错误
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("4059");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("123456");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys("qqqq");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
    }
    private void test4()throws InterruptedException{
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[1]/input")).sendKeys("4059");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[2]/input")).sendKeys("123456");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[3]/input")).sendKeys(str);
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div/div[1]/div[1]/form/div[4]/button")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[4]/div[3]/div/div[1]/div[1]/div[1]/div"));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div/div[1]/a/img")).click();
    }
}
